using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace zoombies__
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        Gamestates currentState = new Gamestates();
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Level level = new Level();
        Player player;
        SlowZombie slowZombie;
        List<SlowZombie> slowList = new List<SlowZombie>();
        int waveCount = 1;
        Random random = new Random();
        Texture2D slowTex;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferHeight = 900;
            graphics.PreferredBackBufferWidth = 1600;
            Content.RootDirectory = "Content";
        }
        protected override void Initialize()
        {
            base.Initialize();
        }
        protected override void LoadContent()
        {
            currentState = Gamestates.InGame;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Texture2D grass = Content.Load<Texture2D>("Grass");
            Texture2D playerTex = Content.Load<Texture2D>("GameThumbnail");
            slowTex = Content.Load<Texture2D>("GameThumbnail");
            level.AddTexture(grass);
            player = new Player(playerTex, new Vector2());
            slowZombie = new SlowZombie(slowTex, new Vector2(), true, 100, 10, 1, slowList);
        }
        protected override void UnloadContent()
        {

        }
        protected override void Update(GameTime gameTime)
        {
            switch(currentState)
            {
                case Gamestates.Intro:
                    {
                        break;
                    }
                case Gamestates.MainMenu:
                    {
                        break;
                    }
                case Gamestates.InGame:
                    {
                        if (slowList.Count == 0)
                        {
                            for (int i = 0; i < 5 * waveCount; i++)
                            {
                                slowList.Add(new SlowZombie(slowTex, new Vector2(random.Next(0, 1000), random.Next(0, 500)), false, 100, 10, 1, slowList));
                            }
                            waveCount++;
                        }
                        foreach (SlowZombie s in slowList)
                            s.Update(gameTime, player.Position);
                        for (int i = 0; i < slowList.Count; i++)
                        {
                            slowList[i].Update(gameTime, player.Position);
                            slowList[i].Moved = false;
                        }
                        player.Update(gameTime, new Vector2());
                        break;
                    }
                case Gamestates.Pause:
                    {
                        break;
                    }
                case Gamestates.Shop:
                    {
                        break;
                    }
            }
            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            switch (currentState)
            {
                case Gamestates.Intro:
                    {
                        break;
                    }
                case Gamestates.MainMenu:
                    {
                        break;
                    }
                case Gamestates.InGame:
                    {
                        level.Draw(spriteBatch);
                        spriteBatch.Draw(player.Texture, player.Position, Color.White);
                        for (int i = 0; i < slowList.Count; i++)
                        {
                            spriteBatch.Draw(slowTex, slowList[i].Position, Color.Red);
                        }
                        break;
                    }
                case Gamestates.Pause:
                    {
                        break;
                    }
                case Gamestates.Shop:
                    {
                        break;
                    }
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
